package Controller.CustomerCompany;
import Dto.CustomerCompany;
import Service.CustomerCompanyService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "updateCustomerCompany", value = "/updateCustomerCompany")
public class UpdateCustomerCompany extends HttpServlet {
    private CustomerCompanyService customerCompanyService = new CustomerCompanyService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Integer id = Integer.valueOf(request.getParameter("id"));
        String name = request.getParameter("name");
        String address = request.getParameter("address");
        String phone = request.getParameter("phone");
        String work = request.getParameter("work");
        CustomerCompany customerCompany = new CustomerCompany();
        customerCompany.setId(id);
        customerCompany.setName(name);
        customerCompany.setAddress(address);
        customerCompany.setPhone(phone);
        customerCompany.setWork(work);
        System.out.println(customerCompany);
        try{
            customerCompanyService.updateCustomerCompany(customerCompany);
            request.getRequestDispatcher("/ListCustomerCompany").forward(request,response);
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}